package com.example.demo.exception;

import com.example.demo.pojo.Result;
import com.mysql.cj.log.LogFactory;
import io.micrometer.observation.GlobalObservationConvention;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.logging.Logger;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandlerAdvice {
    @ExceptionHandler({Exception.class}) //所有异常的统一处理
    public Result HandlerExeception(Exception e, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        log.error("当前捕获到的异常:{}",e.toString());
        return new Result(500, e.toString(), null);
    }
}
